package server

import "fmt"

type ClientMgr struct {
	onlineUsers map[int]*ClientProcess
}

var (
	clientMgr *ClientMgr
)

func init() {
	clientMgr = &ClientMgr{
		onlineUsers: make(map[int]*ClientProcess, 1024),
	}
}

func (c *ClientMgr) AddClient(userID int, client *ClientProcess) {
	c.onlineUsers[userID] = client
}

func (c *ClientMgr) GetClient(userID int) (client *ClientProcess, err error) {
	client, ok := c.onlineUsers[userID]
	if !ok {
		err = fmt.Errorf("user %s not exists", userID)
		return
	}

	return
}

func (c *ClientMgr) GetAllUsers() map[int]*ClientProcess {
	return c.onlineUsers
}
